<template>
	<view v-if="list && list.length" class="relative px-16 py-10 bg-default">
		<view class="mb-12 fs-17 font-bold">为您推荐</view>
		<view class="flex-col">
			<ActivityItem
				v-for="(item,index) in list"
				:key="index"
				:data="item"
				class="mb-16"
				@refresh="queryList"
				@share="toShare(item.id)"
			/>
		</view>
		<share-activity :id="shareId" :show="showSharePopup" @onClose="showSharePopup=false" />
	</view>
</template>

<script setup name="Recommend">
	import {onMounted,ref,unref,computed,getCurrentInstance} from 'vue'
	import {onShow} from '@dcloudio/uni-app'
	import {useUserStore} from '@/stores/modules/user.js'
	import ActivityItem from './ActivityItem.vue'
	import { recommendByBusinessIdApi } from '@/api/activity.js'
	const props = defineProps({
		businessId: { type: String },
		activeId: { type: String },
	})
	const userStore = useUserStore()
	const instance = getCurrentInstance()
	
	const list = ref([])
	
	const showSharePopup = ref(false)
	const shareId = ref('')
	
	const toShare = (id) => {
		if (userStore.isLogin) {
			shareId.value = id
			showSharePopup.value = true
		} else {
			uni.navigateTo({
				url: `/pagesA/login/login?from=${encodeURIComponent(`pages/home/home`)}`,
				events: {
					onLoginSuccess() {
						refresh()
					}
				}
			})
		}
	}
	const queryList = () => {
		recommendByBusinessIdApi({businessId: props.businessId, curActiveId: props.activeId}).then(res => {
			list.value = res
		})
	}
	
	onMounted(() => {
		queryList()
	})
</script>
<style scoped lang="scss">
</style>